//
//  ProductListSortHeader.m
//  BaseProject
//
//  Created by 王洋 on 2020/8/10.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "ProductListSortHeader.h"

@interface ProductListSortHeader ()

@property (nonatomic, assign) BOOL isPricesAscending;


@end
@implementation ProductListSortHeader

- (void)initAllBtn {
    [self.hotBtn setTitleColor:UIColorHex(0x666666) forState:UIControlStateNormal];
    [self.comprehensiveBtn setTitleColor:UIColorHex(0x666666) forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:UIColorHex(0x666666) forState:UIControlStateNormal];
    [self.priceBtn setImage:[UIImage imageNamed:@"sort_nor"] forState:UIControlStateNormal];
}

- (IBAction)comprehensiveAction:(id)sender {
    [self initAllBtn];

    [self.comprehensiveBtn setTitleColor:UIColorHex(0xff4242) forState:UIControlStateNormal];

    if (self.ProductListSortHeaderBlock) {
        self.ProductListSortHeaderBlock(ProductListSortType_Comprehensive);
    }
}

- (IBAction)priceAction:(id)sender {
    [self initAllBtn];
    [self.priceBtn setTitleColor:UIColorHex(0xff4242) forState:UIControlStateNormal];

    if (self.isPricesAscending) {
        [self.priceBtn setImage:[UIImage imageNamed:@"sort_up"] forState:UIControlStateNormal];
        self.isPricesAscending = NO;
        if (self.ProductListSortHeaderBlock) {
            self.ProductListSortHeaderBlock(ProductListSortType_prices_Descending);
        }

    } else {
        [self.priceBtn setImage:[UIImage imageNamed:@"sort_down"] forState:UIControlStateNormal];
        self.isPricesAscending = YES;
        if (self.ProductListSortHeaderBlock) {
            self.ProductListSortHeaderBlock(ProductListSortType_prices_Ascending);
        }
    }
}

- (IBAction)saleAction:(id)sender {
    [self initAllBtn];
    [self.hotBtn setTitleColor:UIColorHex(0xff4242) forState:UIControlStateNormal];

    if (self.ProductListSortHeaderBlock) {
        self.ProductListSortHeaderBlock(ProductListSortType_hot);
    }
}


@end
